package cn.gailvlun.gll.config;

import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class SSLSocketClient {
  
    
    public static SSLSocketFactory getSSLSocketFactory() {
        try {  
            SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, getTrustManager(), new SecureRandom());
            return sslContext.getSocketFactory();  
        } catch (Exception e) {  
            throw new RuntimeException(e);  
        }  
    }  
  
    
    private static TrustManager[] getTrustManager() {
        TrustManager[] trustAllCerts = new TrustManager[]{  
                new X509TrustManager() {
                    @Override  
                    public void checkClientTrusted(X509Certificate[] chain, String authType) {
                    }  
  
                    @Override  
                    public void checkServerTrusted(X509Certificate[] chain, String authType) {  
                    }  
  
                    @Override  
                    public X509Certificate[] getAcceptedIssuers() {  
                        return new X509Certificate[]{};  
                    }  
                }  
        };  
        return trustAllCerts;  
    }  
}  